#ifndef DLGLEASEEDIT_H
#define DLGLEASEEDIT_H

#include <QDialog>
#include "dbmseditor.h"
#include "formtown.h"
#include "formpeople.h"
#include "formdecmasters.h"
#include <QDoubleValidator>
#include <QIntValidator>

namespace Ui {
    class DlgLeaseEdit;
}

class DlgLeaseEdit : public QDialog, public DbmsEditor
{
    Q_OBJECT

    FormTown *mp_te;
    FormPeople *mp_pe;
    FormDecMasters *mp_de;

    QVariantList mqvl_dec_indices;
    QVariantList mqvl_dec_dates;
    QVariantList mqvl_dec_nums;
    QStringList mqsl_ap_sps_ids;
    QVariantHash mqvh_ap_spaces;
    QDoubleValidator *mpq_space_validator;
    QIntValidator       *mpq_num_validator;
    bool m_num_check;

    void setup_connection();
    void data_to_form();
    void form_to_data();
    void showEvent(QShowEvent * ev);
    void update_room_count();
    void dec_list_to_form();
    void update_dec_list_item(int r);
    QString get_dec_list_item_str(int r);
public:
    explicit DlgLeaseEdit(QWidget *parent = 0);
    void set_dbms(HousingDBMS *p_dbms);
    void set_settings(DlgSettings *p_settings);

    inline void disable_num_check() {m_num_check  =  false;}
    ~DlgLeaseEdit();
private slots:
    void dec_date_changed();
    void dec_num_changed();
    void dec_list_sel();
    void data_changed() {m_data_changed = true;}
    void select_apartment(QVariant qv_a_index);
    void select_tenant(QVariant qv_t_index);
    void add_decmaster(QVariant qv_d_index);
    void del_decmaster();
    void accept();


private:
    Ui::DlgLeaseEdit *ui;
};

#endif // DLGLEASEEDIT_H
